{template cashier_header}
<div class="main" style="padding: 0px 10px 0px 10px;">
    <select class="form-control find">
        <option value="0">全部区域</option>
        {loop $regions $region}
        <option value="{$region['id']}" {if $region['id'] == $region_id} selected="selected" {/if}>{$region['name']}</option>
        {/loop}
    </select>

    {loop $my_orders $orders}
    <div class="panel panel-primary">
        <div class="panel-heading">
            <div class="panel-title">
                {$orders['member']}
            </div>
        </div>
        <div class="panel-body">
            <table class="table">
                <tr>
                    <th>商品</th>
                    <th>数量</th>
                    <th>运费</th>
                    <th>代付款</th>
                    <th>手续费</th>
                </tr>
                {loop $orders['goods'] $good}
                <tr>
                    <td>{$good['goods_name']}</td>
                    <td>{$good['numbers']}{$good['unit']}</td>
                    <td>{$good['freight']}</td>
                    <td>{$good['gen_pay']}</td>
                    <td>{$good['charge']}</td>
                </tr>
                <tr>
                    <td colspan="5" align="center">
                        <button class="btn btn-success all" goods_id="{$good['id']}">收齐</button>
                        <button class="btn btn-primary to_get_money" data-toggle="modal" data-target="#myModal" goods_id="{$good['id']}">收款</button>
                        <button class="btn btn-warning" onclick="delay({$good['id']});">缓收</button>
                        <a href="{php echo $this->createMobileUrl('cashier',array('op' => 'change_member','goods_id' => $good['id']))}">
                            <button class="btn btn-danger">更换收款客户</button>
                        </a>
                    </td>
                </tr>
                {/loop}
            </table>
            <div>
                总应收：{$orders['total_price']}
            </div>
            <button class="btn btn-success" onclick="get_all();">全部收齐</button>
        </div>
    </div>
    {/loop}
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">收款内容</h4>
            </div>
            <div class="modal-body">
                <input type="text" class="form-control" placeholder="收到运费" id="had_freight" />
                <input type="text" class="form-control" placeholder="收到代付款" id="had_gen" />
                <input type="text" class="form-control" placeholder="收到手续费" id="had_charge" />
                <input type="text" class="form-control" placeholder="备注" id="had_remark" />
                <input type="hidden" value="0" id="goods_id" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary pay">确定</button>
            </div>
        </div>
    </div>
</div>
<script>
    $(function(){
        $(".to_get_money").click(function(){
            var goods_id = $(this).attr('goods_id');
            $("#goods_id").val(goods_id);
        });
        $(".pay").click(function(){
            var goods_id = $("#goods_id").val();
            var had_freight = $("#had_freight").val();
            var had_gen = $("#had_gen").val();
            var had_remark = $("#had_remark").val();
            var had_charge = $("#had_charge").val();
            $.ajax({
                type : "post",
                url : "{php echo $this->createMobileUrl('cashier',array('op' => 'get_money'))}",
                data : {'goods_id' : goods_id, 'had_freight' : had_freight, 'had_gen' : had_gen, 'had_remark' : had_remark,'had_charge' : had_charge},
                success : function(data){
                    if(data == 111){
                        location.reload();
                    }else{
                        alert(data);
                    }
                }
            });
        });
        $(".all").click(function(){
            var goods_id = $(this).attr('goods_id');
            if(confirm("是否确定全部收齐？")){
                $.ajax({
                    type : "post",
                    url : "{php echo $this->createMobileUrl('cashier',array('op' => 'get_money'))}",
                    data : {'goods_id' : goods_id, 'type' : 'all'},
                    success : function(data){
                        if(data == 111){
                            location.reload();
                        }else{
                            alert(data);
                        }
                    }
                });
            }
        });
        $(".find").change(function(){
            var region_id = $(this).val();
            location.href="{php echo $this->createMobileUrl('cashier',array('op' => 'index'))}&region_id="+region_id;
        });
    });
    function delay(id){
        if(confirm("是否确定设置成缓收？")){
            $.ajax({
                type : "post",
                url : "{php echo $this->createMobileUrl('cashier',array('op' => 'slow'))}",
                data : {'id' : id},
                success : function(data){
                    location.reload();
                }
            });
        }
    }
    function get_all(){
        if(confirm("一经确定无法修改，是否确定已经收取了所有的款项？"));
    }
</script>
{template 'footer'}